/*
 * FlashcardRecorder for flashcard project
 *
 * Author: Thong Nguyen
 * Version: 1.1
 * Date: October 15, 2012
 */

	'use strict';
	
	$.thisMovie = function(movieName) {
	    if (navigator.appName.indexOf("Microsoft") != -1) {
	        version = parseInt($.browser.version, 10);
	        return version >=9 ? document[movieName] : window[movieName];
	    } else {
	        return document[movieName];
	    }
	};
	
	/**
	 * Create recorder
	 */
	function fcRecorder(options) {
		
		var def = {
			id: 'fcrecorder', //the id of component
			enable: [], //enable functions
			container: 'body', //the container that store the component
			width: 220, //the width
			height: 150, //the height
			swfpath: "fcRecorder.swf",
			server: "rtmp://localhost",
			ready: null
		};
		
		if(options)
			def = $.extend(def, options);
		
		this.options = def;
		
		var objStr = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "
			+ "id='" + def['id'] + "' width='" + def['width'] + "' height='" + def['height'] + "' "
			+ "codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' style='position:absolute;left:0;top:0;z-index:100;'> "
			+ "<param name='movie' value='" + def['swfpath'] + "' /> "
			+ "<param name='quality' value='high' /> "
			+ "<param name='wmode' value='transparent' /> "
			+ "<param name='FlashVars' value='recorderid=" + def['id'] + "&server=" + def['server'] + "' /> "
			+ "<param name='allowScriptAccess' value='sameDomain' /> "
			+ "<param name='allowFullScreen' value='false' /> "
			+ "<embed src='" + def['swfpath'] + "' width='" + def['width'] + "' height='" + def['height'] + "' name='"+ def['id'] +"' align='middle' "
			+ "play='true' FlashVars='recorderid=" + def['id'] + "&server=" + def['server'] + "' "
			+ "wmode='transparent' "
			+ "loop='false' "
			+ "quality='high' "
			+ "allowFullScreen='true' "
			+ "allowScriptAccess='sameDomain' "
			+ "type='application/x-shockwave-flash' "
			+ "pluginspage='http://www.adobe.com/go/getflashplayer'/></object>";
		
		$(objStr).appendTo($(def['container']));
		this.objFlash = $.thisMovie(def['id']);
		
		$.fcRecorder = this;
		
		if(def.ready)
			def.ready();
	}
	